import java.io.*;
import java.net.*;
import java.util.*;

public class TCPListener {
	/**
     * Fields
     */
    private Socket incoming;
    private BufferedReader inStream;
    private BufferedWriter outStream;
    private Scanner scannerIn;
    private PrintWriter printOut;

    public TCPListener() throws IOException{
        ServerSocket socket = new ServerSocket(3);
        acceptConnection(socket);
    }
    /**
     * @param socket
     * @throws IOException
     */
    public void acceptConnection(ServerSocket socket) throws IOException {
        incoming = socket.accept();
        System.out.println("socket port: "+socket.getLocalPort());
        System.out.println("incoming port: "+incoming.getPort());
        inStream = new BufferedReader(new InputStreamReader(incoming.getInputStream()));
        outStream = new BufferedWriter(new OutputStreamWriter(incoming.getOutputStream()));
        scannerIn = new Scanner(inStream);
        printOut = new PrintWriter(outStream, true /* Auto flush */);
    }
    
    public void instream() {
    	if(scannerIn.hasNextLine()) {
    		System.out.println(scannerIn);
    	} else if(scannerIn.nextLine().equals("q")) {
    		
    	}
    }
}